import { createRouter, createWebHistory } from 'vue-router'
import home from '../views/Home/home.vue'


const routes = [{
    path: '/',
    component: () => import('../views/login/login.vue')
}, {
    path: '/home',
    component: home,
    children: [
        //     {
        //     path: 'center',
        //     component: () =>
        //         import ('../views/Center/Center.vue')
        // }, 
        // {
        //     path: 'star',
        //     component: () =>
        //         import ('../views/StarService/StarService.vue')
        // }, {
        //     path: 'send',
        //     component: () =>
        //         import ('../views/Send/Send.vue')
        // }, 
        {
            path: 'show',
            component: () =>
                import('../views/Show/Show.vue')
        },
        {
            path: 'tabs',
            component: () =>
                import('../components/tabs.vue'),
            children: [
                {
                    path: 'center',
                    component: () =>
                        import('../views/Center/Center.vue')
                },
                {
                    path: 'star',
                    component: () =>
                        import('../views/StarService/StarService.vue')
                }, {
                    path: 'send',
                    component: () =>
                        import('../views/Send/Send.vue')
                },
                {
                    path: 'initial',
                    component: () =>
                        import('../views/Initial/Initial.vue')
                },
            ]
        },
        //  {
        //     path: 'initial',
        //     component: () =>
        //         import ('../views/Initial/Initial.vue')
        // },
        {
            path: 'system',
            component: () =>
                import('../views/System/system.vue')
        },
        {
            path: 'setPassword',
            component: () =>
                import('../views/setPassword/setPassword.vue')
        },
        {
            path: 'showIp',
            component: () =>
                import('../views/showIp/showIp.vue')
        },
        {
            path: 'setIp',
            name: 'setIp',
            component: () =>
                import('../views/showIp/setIp.vue')
        },
        {
            path: 'userList',
            component: () =>
                import('../views/userList/userList.vue')
        },
        {
            path: 'logs',
            component: () =>
                import('../views/logs/logs.vue')
        }
    ]
}]

const router = createRouter({
    history: createWebHistory(process.env.BASE_URL),
    routes
})
router.beforeEach(async (to, from, next) => {
    if (to.path === '/') {
        next();
    } else {
        const token = sessionStorage.getItem('isL');
        if (!token) {
            next('/')
        } else {
            next();
        }
    }
})

export default router